#ifndef HLS_CLIENT_H_
#define HLS_CLIENT_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

class Loop;
class HttpHlsConnection;
class HlsM3U8Message;
class HlsClient
{
public:
    explicit HlsClient(Loop * loop);
    void MediaFilePath(const std::string & path);
    void M3uFilePath(const std::string & path);
    void Download(const std::string & url);

private:
    void OnM3UMessage(HlsM3U8Message * message);
    void OnMediaFile(const std::string & url, const uint8_t * data, int length);
    void WriteM3U8Data(HlsM3U8Message * message);
    void WriteMediaData(const std::string & url, const uint8_t * data, int length);

private:
    std::string m_media_path;
    std::string m_m3u_path;
    std::string m_url;
    struct MediaData
    {
        std::string m_raw_uri;
    };
    std::map<std::string, MediaData> m_media_url_map;
    bool                             m_need_fetch_media_url;

private:
    Loop *                             m_loop;
    std::shared_ptr<HttpHlsConnection> m_connection;
    bool                               m_write_to_file;
};

#endif
